import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "",
    // name: "Layout", 在vue-router中,当有子路由的时候,父级路由需要一个默认的路由,所以这个时候不能给父级路由设置name属性
    component: () => import("../views/Layout/index.vue"),
    //配置路由元信息
    meta: {
      isLogin: true,
    },
    children: [
      {
        path: "/",
        name: "Home",
        component: () => import("../views/Home/index.vue"),
      },
      {
        path: "/goods",
        name: "Goods",
        component: () => import("../views/Goods/Goods.vue"),
      },
      {
        path: "/add-goods",
        name: "AddGoods",
        component: () => import("../views/Goods/AddGoods.vue"),
      },
      {
        path: "/params",
        name: "Params",
        component: () => import("../views/Params/Params.vue"),
      },
      {
        path: "/advert",
        name: "Advert",
        component: () => import("../views/Advert/Advert.vue"),
      },
      {
        path: "/order",
        name: "Order",

        component: () => import("../views/Order/Order.vue"),
        redirect: "/order/order-list", //路由的重定向
        children: [
          {
            path: "order-list",
            name: "OrderList",
            component: () => import("../views/Order/OrderList/index.vue"),
          },
          {
            path: "order-back",
            name: "OrderBack",
            component: () => import("../views/Order/OrderBack/index.vue"),
          },
        ],
      },
    ],
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("../views/Login/Login.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
